<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@ include file="/include/service-base-header.jsp" %>
    <title>分销商管理</title>

    <style>
        .card {
            margin-top: 0px;
            margin-bottom: 0px;
        }
    </style>

</head>
<body>
<div class="wrapper">
    <jsp:include page="/include/left_menu.jsp">
        <jsp:param name="index" value="4"/>
    </jsp:include>
    <div class="main-panel">
        <nav class="navbar navbar-expand-lg navigation_shadow_none">
            <div class="container-fluid">
                <div class="navbar-wrapper b-navbar-wapper">
                    <a class="b-navbar-title-active"
                       href="${pageContext.request.contextPath}/s/distribution.do">分销商管理</a>
                    <a class="b-navbar-title" href="${pageContext.request.contextPath}/s/sales-withdraw.do">佣金提现申请</a>
                </div>
            </div>
        </nav>
        <div style="background: #EEEEEE;height: 1px"></div>
        <nav class="navbar navbar-expand-lg "
             style="-webkit-box-shadow:0 0 5px rgba(40, 173, 243, 0.0);box-shadow: 0 0 5px rgba(40, 173, 243, 0.0);">
            <div class="container-fluid">
                <div class="navbar-wrapper">
                    <a href="#"
                       onclick="window.history.go(-1)"
                       style="font-size: 0.9rem;margin-left: 0.2rem">二级分销商会员明细</a>
                    <span style="font-size: 0.9rem;">&nbsp; / &nbsp;充值明细</span>
                </div>
            </div>
        </nav>
        <div class="container-fluid">
            <div class="row" style="margin-top: 3rem">
                <div class="col-md-12">
                    <div class="card card-plain">
                        <div class="card-header card-header-primary">
                            <div class="card-title">会员充值列表</div>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table" id="table">
                                    <thead class=" text-primary">
                                    <tr>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            #
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            充值时间
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            充值金额
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            返佣比例
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            二级返佣金额
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <nav aria-label="page">
                        <ul class="pagination justify-content-center" id="p1">
                        </ul>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>

</body>

<script>
    var data_source;
    var page_count = 15;
    findSalesList();
    function findSalesList() {
        var data = {};
        var userId = baseFn.getQueryString('userId');
        data.userId = userId;
        $.ajax({
            url: baseUrl.base + baseUrl.sales + "/salesDetail",
            type: 'get',
            data: data,
            success: function (data) {
                if (data.code == "0") {
                    var res = data.results;
                    data_source = res;
                    cutPagination(1);

                    // 配置分页
                    $("#p1").pagination({
                        totalData: res.length,
                        showData: page_count,
                        callback: function (idx) {
                            cutPagination(idx);
                        }
                    });
                } else {
                    var res = data.msg;
                    alert(res);
                }
            }
        });
    };

    /**
     * 分页
     * @param page 从1开始
     */
    function cutPagination(page) {

        var start = (page - 1) * page_count;
        var end = start + page_count;

        if (end > data_source.length) {
            end = data_source.length;
        }

        $("#tbody").empty();

        for (var i = start; i < end; i++) {
            var sales = data_source[i];

            var tr = document.createElement("tr");
            var td = document.createElement("td");
            var tdContent = document.createTextNode(i + 1);
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(timestampToTime(sales.rechageTime));
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            var name = document.createTextNode(sales.rechageMoney + "KSH");
            td.appendChild(name);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(sales.backRate);
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(sales.backMoney + "KSH");
            td.appendChild(tdContent);
            tr.appendChild(td);

            document.getElementById("tbody").append(tr);
            document.getElementById("tbody").innerHTML;
        }
    }
</script>
</html>